tools/xenstat: Fix -Wformat-truncation= issue
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 13 Aug 2019 13:46:00 +0000 (14:46 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 14 Aug 2019 11:04:20 +0000 (12:04 +0100)
commit435e985b10905845800170e711e5307c12b413e3
tree44b0f9115aa035fe8b57e4060beed453cd96ec20
parent02378ea85c23ae914c0b0b19604ceff138f0f4dd
tools/xenstat: Fix -Wformat-truncation= issue

Building with GCC 8.3 on Buster identifies:

  src/xenstat_linux.c: In function 'xenstat_collect_networks':
  src/xenstat_linux.c:307:32: warning: 'snprintf' output may be truncated before
  the last format character [-Wformat-truncation=]
    snprintf(devNoBridge, 16, "p%s", devBridge);
                                  ^
  src/xenstat_linux.c:307:2: note: 'snprintf' output between 2 and 17 bytes into
  a destination of size 16
    snprintf(devNoBridge, 16, "p%s", devBridge);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

devNoBridge[] needs one charater more than devBridge[], so allocate one byte
more.  Replace a raw 16 in the snprintf() call with a sizeof() expression
instead.

Finally, libxenstat, unlike most of the rest of the Xen, doesn't use -Werror
which is why this issue went unnoticed in CI.  Fix this.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wl@xen.org>
tools/xenstat/libxenstat/Makefile
tools/xenstat/libxenstat/src/xenstat_linux.c